﻿#version 420
uniform sampler2D DiffTexture;
uniform sampler2D PosTexture;
uniform sampler2D NormTexture;
uniform vec3 LightPosition;
uniform vec3 LightColor;
uniform vec2 WindowSize;

in vec3 f_Position;
in vec3 f_Normal;

out vec4 out_Color;

void main(void)
{
    vec2 texc = gl_FragCoord.xy / WindowSize;
    vec3 pos = texture(PosTexture, texc).xyz;
    vec3 norm = texture(NormTexture, texc).xyz;
	vec4 diff = texture(DiffTexture, texc);

    vec3 lightVec = normalize (LightPosition - pos);
	vec3 viewVec = normalize (-pos);
	vec3 halfVec = normalize (lightVec + viewVec);
	vec3 normVec = normalize (norm);

    vec3 dif = diff.xyz * max(0, dot(normVec, lightVec));
	float spc = pow(max(0, dot(normVec, halfVec)), diff.w);

    if( pos.z > -0.01 && pos.z < 0.01) {
	    out_Color = vec4 (1,0,0,1);
	}else{
        /*out_Color = vec4 (dif*LightColor + spc*LightColor, 1);*/
        /*out_Color = vec4 (1.0, 1.0, 0.0, 1.0);*/
	    out_Color = vec4 (pos.x, pos.y, pos.z, 1);
    }
}

